<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useUserStore } from "/@/store/user";

const refreshLock = ref(false);
const userStore = useUserStore();
let timer: any;
const refreshToken = function () {
  if (timer) {
    clearInterval(timer);
  }
  timer = setInterval(async () => {
    if (!refreshLock.value) {
      try {
        refreshLock.value = true;
        await userStore.refreshTokens();
        refreshLock.value = false;
        console.log('token刷新成功');
      } catch (error) {
        console.log(error);
        userStore.logout()
      }
    }
  }, 100000);
};
onMounted(() => refreshToken())

</script>

<template>
  <router-view></router-view>
</template>

<style>
</style>
